package com.cykj.eurekaclient.service.impl;

import com.alibaba.fastjson.JSON;
import com.cykj.eurekaclient.bean.CityInfo;
import com.cykj.eurekaclient.bean.RouteInfo;
import com.cykj.eurekaclient.bean.StationInfo;
import com.cykj.eurekaclient.mapping.StationAssignMapper;
import com.cykj.eurekaclient.mapping.StationInfoMapper;
import com.cykj.eurekaclient.service.StationInfoService;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StationInfoServiceImpl implements StationInfoService {

    @Autowired
    StationInfoMapper stationInfoMapper;

    @Autowired
    StationAssignMapper stationAssignMapper;

    /**
     * @version 1.0
     * @author: zhiMing
     * @date: 2021/9/24 17:00
     * @desc: 根据地区信息，获取对应的站点集合
     */
    @Override
    public CityInfo getStationList(String district) {

        CityInfo cityInfo = stationInfoMapper.getStationList(district);
        System.out.println(district+" client");

        List<StationInfo> stationInfoList = JSON.parseArray(cityInfo.getStationInfoListStr(),StationInfo.class);
        cityInfo.setStationInfoList(stationInfoList);
        for (StationInfo sI: stationInfoList) {
           List<RouteInfo> routeList = stationAssignMapper.getRouteList(sI.getId());
           if (routeList!=null&& routeList.size() != 0){
               for (RouteInfo routeInfo:routeList){
                   List<StationInfo> stationInfoList2 = JSON.parseArray(routeInfo.getRouteStationInfoListStr(),StationInfo.class);
                   routeInfo.setRouteStationInfoList(stationInfoList2);
                   routeInfo.setRouteStationInfoListStr("");
               }
               sI.setRouteList(routeList);
           }
        }
        return cityInfo;
    }
}
